home *** CD-ROM | disk | FTP | other *** search
- /*************************************************
- * This is loaded in the main xul document
- *************************************************/
-
- const YOONO_ID = "{d9284e50-81fc-11da-a72b-0800200c9a66}";
- const YOONO_WMED = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator);
-
-
- /*
- * This class, defined here, is enriched in sidebarPanel.js
- * An instance is created when FF is started, and kept session-wide
- * However, the init method of the instance is called each time the sidebar is opened
- * the init method is defined in sidebarPanel.js, which is loaded
- * in the sidebarPanel.xul document loaded when the sidebar is opened
- */
- function YoonoSidebar(externalInterfaces) {
- try {
- var _self = this;
- this.visible = false; // sidebar visible or not, this flag is handled by xul document loading and unloading...
- this.container = document.getElementById('yoono-sidebar-box');
- this.browser = document.getElementById('yoono-sidebar');
- // Get the skin chosen by user
- var skinName = YNPREFBRANCH.getCharPref("skin");
-
- this.browser.setAttribute('skin', skinName);
-
- this.splitter = document.getElementById('yoono-splitter');
- // define services made available to external calls
- this.externalInterfaces = externalInterfaces;
- this.methods = externalInterfaces.methods;
- // at startup, sidebar might be opened because it was last time
- // In order for everything to be ready, the sidebar browser is loaded just now
- this.showIfVisible();
- // Init splitter movement detection
- if(this.splitter) {
- this.splitter.addEventListener('mousedown', function(evt) {_self.splitterMouseDown(evt)}, false);
-
- }
- this.resizing = false;
- this.thin = false;
- } catch(e) {
- YOONO_LOG.exception(e);
- }
- }
-
- YoonoSidebar.prototype.splitterMouseDown = function(evt) {
-
- var _self = this;
-
- var initialWidth = parseInt(this.browser.parentNode.getAttribute('width'));
- var initialX = evt.screenX;
- var previousX = evt.clientX;
-
- function mouseUp(evt) {
- YOONO_LOG.debug('YoonoSidebar.splitterMouseUp');
- document.removeEventListener('mouseup', mouseUp, true);
- document.removeEventListener('mousemove', mouseMove, true);
- }
-
- function mouseMove(evt) {
- var direction = (evt.clientX > previousX)?'right':'left';
- previousX = evt.clientX;
-
- var diffX=evt.screenX - initialX;
-
- var width = initialWidth+diffX;
- if(width >= 700) return;
- //dump("mouse move -- resize --> "+width+" - "+direction+"\n");
-
- if ('ynSidebar' in _self.win) {
- width = _self.win.ynSidebar.getResizeWidth(width, direction);
- }
-
- _self.browser.parentNode.setAttribute('width',width);
- }
-
- YOONO_LOG.debug('YoonoSidebar.splitterMouseDown with ' + initialWidth);
- document.addEventListener('mouseup', mouseUp, true);
- document.addEventListener('mousemove', mouseMove, true);
- }
-
- YoonoSidebar.prototype.toggleThin = function(thinWidth) {
- if(this.thin) {
- this.win.ynSidebar.setLarge();
- } else {
- this.win.ynSidebar.setThin(false);
- }
- }
-
- YoonoSidebar.prototype.setThin = function(thinWidth) {
- this.thin = true;
- YOONO_LOG.debug('YoonoSidebar.setThin');
- this.browser.parentNode.setAttribute('class', 'sidebar thin');
- this.browser.parentNode.setAttribute('width', thinWidth);
- }
-
- YoonoSidebar.prototype.setLarge = function(largeWidth) {
- this.thin = false;
- this.browser.parentNode.setAttribute('class', 'sidebar large');
- YOONO_LOG.debug('YoonoSidebar.setLarge');
- this.browser.parentNode.setAttribute('width', largeWidth);
- }
-
- YoonoSidebar.prototype.showManageBookmarks = function() {
- var userCredential = YOONO_CMPT.getUserCredential();
- if(!this.visible || !this.win.ynSidebar || !userCredential || userCredential.anonymous) {
- alert(yoonoGlob.gStrbundle.getString('bkms.open.sidebar'));
- return;
- }
- this.win.ynSidebar.showManageBookmarks();
- }
-
- YoonoSidebar.prototype.isVisible = function() {
- return(this.visible); // flag handled by the loading/unloading of the xul sidebar document
- }
-
- /**
- * check if sidebar was visible last time
- * and open the sidebar accordingly
- */
- YoonoSidebar.prototype.showIfVisible = function() {
- if(!this.container) return;
- var hidden = this.container.getAttribute('hidden');
- // Open the sidebar if updated or it was opened last time
- if(yoonoGlob.firstReleaseRun || ('true' != hidden)) {
- this.show();
- }
- }
-
- YoonoSidebar.prototype.show = function() {
- if(!yoonoGlob.tosAccepted) {
- this.loadTOSXulDoc();
- return;
- }
-
- if(!this.container) return;
- YOONO_CMPT.addStat(['sidebar', 'open'])
- this.container.removeAttribute('hidden');
- this.splitter.removeAttribute('hidden');
- this.loadSidebarXulDoc();
- }
-
- YoonoSidebar.prototype.loadTOSXulDoc = function() {
- YOONO_LOG.debug('YoonoSidebar.show displaying TOS');
- var sbUrl = 'chrome://yoono/content/TOSPanel.xul';
- this.browser.parentNode.setAttribute("class", "tos");
- this.browser.parentNode.setAttribute("style","max-width:300px;");
- this.browser.parentNode.setAttribute("style","min-width:100px;");
- this.browser.setAttribute('src', sbUrl);
- this.container.removeAttribute('hidden');
- this.splitter.removeAttribute('hidden');
- }
-
- YoonoSidebar.prototype.loadSidebarXulDoc = function() {
- YOONO_LOG.debug('YoonoSidebar.show displaying Sidebar');
- var sbUrl = 'chrome://yoono/content/sidebarPanel.xul';
- this.browser.parentNode.setAttribute("style","max-width:0px;");
- this.browser.parentNode.setAttribute("class", "sidebar");
- this.browser.setAttribute('src', sbUrl);
- }
-
- YoonoSidebar.prototype.hide = function() {
- YOONO_LOG.debug('YoonoSidebar.hide');
- if (this.uninit)
- this.uninit(); // this method is defined in sidebarPanel.js
- if(this.container) {
- this.container.setAttribute('hidden', true);
- this.splitter.setAttribute('hidden', true);
- }
- this.browser.setAttribute('src', '');
- }
-
-
- YoonoSidebar.prototype.toggle = function() {
- YOONO_LOG.debug('YoonoSidebar.toggle : ' + this.visible);
- var hidden = this.container.getAttribute('hidden') || false ;
- if(hidden) {
- this.show();
- } else {
- this.hide();
- }
- return(!hidden);
- }
-
-